#ifndef _CLIENT_HEAD_H
#define _CLIENT_HEAD_H

#include <my_header.h>
#include <openssl/md5.h>
typedef enum
{
    USER_REGI,
    USER_LOGIN1,
    USER_LOGIN2,
    L_R_SUCCESS,
    L_R_ERR,
    

    C_OP_CD,
    CD_SUCCESS,
  

    C_OP_LS,
    LS_SUCCESS,


    C_OP_RMDIR,
    RMDIR_SUCCESS,


    C_OP_MKDIR,
    MKDIR_SUCCESS,

    C_OP_REMOVE,
    REMOVE_SUCCESS,

    DIR_ERR,

    C_OP_PUTS_QUERY,
    RES_PUTS_COMFIRM,
    C_OP_PUTS_BEGIN,

    C_OP_GETS_QUERY,
    RES_GETS_COMFIRM,
    C_OP_GETS_BEGIN
}MSG_TYPE;

typedef struct
{
    MSG_TYPE type;
    int args_len;
    char args_val[1024];
}RequestPackage;

typedef struct
{
    MSG_TYPE type;
    int args_len;
    char args_val[1024];
}ResponsePackage;

typedef struct pthread_data_s {
    pthread_t *ptidarr;
    int workernum;
} pthread_data_t;

typedef struct 
{
//     pthread_data_t  *pthread_data;
    // int *exitflag;  // 退出标志位
    // int *download_pipe;// 下载管道文件描述符
    // int *upload_pipe;  // 上传管道文件描述符

    // int father_s_netfd;
    // int user_id;
    // int now_path_id;

int client_choose;
off_t file_size;
MSG_TYPE type;
int args_len;
char agrs[1024];

} shareRes_t;


// 客户端解析器 
int send_resolver(char *statement, RequestPackage *prequest);
int recv_resolver(int target,int args_len,char*args,char*now_path_buf,int sockfd);

//client_api.c
int client_cd(int target,int args_len,char *args,int netfd,char *now_path_buf); 
int client_ls(int target,int args_len,char *args,int netfd,char *now_path_buf);
int client_pwd(int target,int args_len,char *args,int netfd,char *now_path_buf);
int client_mkdir(int target,int args_len,char *args,int netfd,char *now_path_buf);
int client_rmdir(int target,int args_len,char *args,int netfd,char *now_path_buf);
int client_rmfile(int target,int args_len,char *args,int netfd,char *now_path_buf);
// int client_puts(ResponsePackage *presponse,const ClientVirtualPathStack* pvirtualpathstack,const int socked_fd);
// int client_gets(ResponsePackage *presponse,const ClientVirtualPathStack* pvirtualpathstack,const int socked_fd);
int recvn(int netfd, void *buf, long len, long *pProcessed);

// epoll连接相关
int epollAdd(int epfd, int addfd, int trigger);
int epollDel(int epfd, int delfd);

// TCP连接相关
int initTcp(char *ip, char *port);

// 线程相关
int init_pthread_data(pthread_data_t *pthread_data, int pthread_num);
int makeworker(shareRes_t *share, pthread_data_t *pthread_data, int *exitFlag,int *download_pipe,int *upload_pipe);
void *download_enter(void *arg);
void *upload_enter(void *arg);

// simple_judge
int recv_resolver(int target, int args_len, char *args, char *now_path_buf, int sockfd);
int submit(int netfd, char *buf, int target);
int simplejudge(char *readbuf, int *target, char *now_path_buf);
int checkout_num(const char *buf);
int getstr(const char *src, int n, char *dest, size_t dest_size);
int split_path(const char *input, char **out_parent, char **out_name);
int CalMD5(char* filepath, char* md5);

// 创建salt
int salt_create(char *desc);

// 传输文件
int client_puts_comfirm(int target, int args_len, char *args, int netfd, char *now_path_buf);


#endif
